package com.vicente.managerdemo.controller;

import com.vicente.managerdemo.common.ResultBean;
import com.vicente.managerdemo.dto.MenuQueryDto;
import com.vicente.managerdemo.dto.MenuVO;
import com.vicente.managerdemo.entity.Menu;
import com.vicente.managerdemo.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 系统菜单信息表 前端控制器
 * </p>
 *
 * @author vicente
 * @since 2024-12-04
 */
@RestController
@RequestMapping("/menu")
public class MenuController {

    @Resource
    private MenuService menuService;

    /**
     * @Description: 保存菜单数据，包含新增和修改
     **/
    @RequestMapping("/save")
    public ResultBean save(@RequestBody Menu menu){
       return menuService.saveMenu(menu);
    }

    /**
     * @Description: 删除菜单数据，如有子菜单，会一同删除
     **/
    @RequestMapping("/delete/{menuId}")
    public ResultBean delete(@PathVariable Long menuId){
        return menuService.delete(menuId);
    }

    /**
     * @Description: 查询菜单数据
     **/
    @RequestMapping("/list")
    public ResultBean listMenu(@RequestBody MenuQueryDto queryDto){
        return menuService.listMenu(queryDto);
    }

    /**
     * @Description: 查询菜单数据，构建树状结构
     **/
    @RequestMapping("/listTree")
    public ResultBean listTreeMenu(@RequestBody MenuQueryDto queryDto){
        List<MenuVO> sysMenuVOList = menuService.listTreeMenu(queryDto);
        return ResultBean.getSuccess(sysMenuVOList);
    }

}
